package com.honghe.system.controller;

import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.honghe.common.annotation.Log;
import com.honghe.common.core.controller.BaseController;
import com.honghe.common.core.domain.AjaxResult;
import com.honghe.common.core.page.TableDataInfo;
import com.honghe.common.enums.BusinessType;
import com.honghe.system.domain.Cases;
import com.honghe.system.service.ICasesService;

/**
 * 客户案件 信息操作处理
 * 
 * @author honghe
 */
@RestController
@RequestMapping("/system/case-assign")
public class SysCaseController extends BaseController
{
    @Autowired
    private ICasesService casesService;

    /**
     * 查询客户案件列表
     */
    @PreAuthorize("@ss.hasPermi('system:cases:list')")
    @GetMapping("/list")
    public TableDataInfo list(Cases cases)
    {
        startPage();
        List<Cases> list = casesService.selectCasesList(cases);
        return getDataTable(list);
    }

    /**
     * 获取客户案件详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:cases:query')")
    @GetMapping(value = "/{caseId}")
    public AjaxResult getInfo(@PathVariable("caseId") Long caseId)
    {
        return success(casesService.selectCasesByCaseId(caseId));
    }

    /**
     * 新增客户案件
     */
    @PreAuthorize("@ss.hasPermi('system:cases:add')")
    @Log(title = "客户案件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Cases cases)
    {
        return toAjax(casesService.insertCases(cases));
    }

    /**
     * 修改客户案件
     */
    @PreAuthorize("@ss.hasPermi('system:cases:edit')")
    @Log(title = "客户案件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cases cases)
    {
        return toAjax(casesService.updateCases(cases));
    }

    /**
     * 删除客户案件
     */
    @PreAuthorize("@ss.hasPermi('system:cases:remove')")
    @Log(title = "客户案件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{caseIds}")
    public AjaxResult remove(@PathVariable Long[] caseIds)
    {
        return toAjax(casesService.deleteCasesByCaseIds(caseIds));
    }

    /**
     * 分配案件
     */
    @PreAuthorize("@ss.hasPermi('system:cases:assign')")
    @Log(title = "案件管理", businessType = BusinessType.UPDATE)
    @PostMapping("/assign")
    public AjaxResult assign(@RequestBody Map<String, Long> params)
    {
        Long caseId = params.get("caseId");
        Long assignedUserId = params.get("assignedUserId");
        return toAjax(casesService.assignCase(caseId, assignedUserId));
    }
} 